# To change this template, choose Tools | Templates
# and open the template in the editor.

$:.unshift File.join(File.dirname(__FILE__),'..','lib')

require 'test/unit'
require 'graphics'

class Test_Graphics < Test::Unit::TestCase
#####################################################################
#Typen 1d-Objekte 
   def test_union1d
      range1 = (11..12)
      range2 = (12..13)
      range3 = (1..2)
      range4 = (2..3)
      
      union1 = Union1d[range1,range2]
      union2 = Union1d[range3,range4]
      
      assert_equal(Union1d[range1,range2],Union1d[range1,range2])
      assert_equal(Union1d[union1,range2],Union1d[union1,range2])
      #Translation
      assert_equal(range1,trans1d(range3,10))
      #Neutrales Element
      assert_equal(range3,trans1d(range3,0))
      #Inverse
      assert_equal(range3,trans1d(trans1d(range3,10),-10))
      #Akkumulation
      assert_equal(trans1d(range3,(5+10)),trans1d(trans1d(range3,5),10))
      #Union
      assert_equal(union1,trans1d(union2,10))
   end
#####################################################################
#Typen 2d-Objekte
   def test_point2d
      assert_equal(Point2d[1,2],Point2d[1,2])
   end
   def test_range2d
      range = (12..14)
      assert_equal(Range2d[range,range],Range2d[range,range])
   end
   def test_shape2d
      range = (12..14)
      range2 = Range2d[range,range]
      assert_equal(range2,range2)
      assert_equal(Union2d[range2,range2],Union2d[range2,range2])
      #assert_raise(RuntimeError){'a'}
   end
   def test_union2d
     range = (12..14)
     range2 = Range2d[range,range]
     assert_equal(Union2d[range2,range2],Union2d[range2,range2])
     #assert_raise(RuntimeError){Union2d[range2,'a']}
     #assert_raise(RuntimeError){Union2d['a',range2]}
   end
#####################################################################
#Typen Shared-Objekte
   def test_point
     assert_equal(12,12)
     assert_equal(Point2d[12,14],Point2d[12,14])
     #assert_raise(RuntimeError){Point['a']}
   end
   def test_primshape
     assert_equal((12..14),(12..14))
     assert_equal(Range2d[(12..14),(12..14)],Range2d[(12..14),(12..14)])
     #assert_raise(RuntimeError){PrimShape['a']}
   end
   def test_unionshape
     range = (12..14)
     union = Union1d[range,range]
     
     range2 = Range2d[range,range]
     union2 = Union2d[range2,range2]
     assert_equal(union,union)
     assert_equal(union2,union2)
     #assert_raise(RuntimeError){'a'}
   end
   def test_compshape
     range = (12..14)
     union = Union1d[range,range]
     
     range2 = Range2d[range,range]
     union2 = Union2d[range2,range2]
     
     assert_equal(union,union)
     assert_equal(union2,union2)
     #assert_raise(RuntimeError){CompShape['a']}
   end
   def test_shape
     range  = (12..14)
     union  = Union1d[range,range]
     
     assert_equal(union,union)
     assert_equal(range,range)
     #assert_raise(RuntimeError){Shape['a']}
   end
   def test_graphobj
     range  = (12..14)
     union  = Union1d[range,range]
    
     #assert_equal(graph_obj(Point[12]),graph_obj(Point[12]) )
     #assert_equal(graph_obj(comp),graph_obj(comp) )
     #assert_equal(graph_obj(prim),graph_obj(prim) )
     assert_equal(12,12)
     assert_equal(union,union )
     assert_equal(range,range )
  end
  
  def test_bounds
     range1  = (12..16)
     range2  = (22..28)
     range3  = (32..35)
     range4  = (42..44)
     range2d1 = Range2d[range1,range2]
     range2d2 = Range2d[range3,range4]
     union  = Union1d[range1,range2]
     union2 = Union2d[range2d1,range2d2] 
      
     assert_equal((12..28),bounds(union))
     assert_equal(range1,bounds(range1))
     assert_equal(Range2d[(12..35),(22..44)],bounds(union2))
     assert_equal(range2d1,bounds(range2d1))
  end
  def test_in_shape
    range1  = (1..4)
    range2  = (2..6)
    range3  = (7..12)
    range4  = (13..19)
    range2d1  = Range2d[range1,range2]
    range2d2  = Range2d[range3,range4]
    union  = Union1d[range1,range2]
    union2 = Union2d[range2d1,range2d2] 
   
    point1 = 5
    point2 = 8
    point3 = Point2d[8,43]
       
    assert_equal(true,in_shape?(point1,union))
    assert_equal(false,in_shape?(point1,range1))
    assert_equal(false,in_shape?(point3,union2))
    assert_equal(false,in_shape?(point2,range1))
  end
end


